package com.tjshop.android.model;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by gytaiSSD on 2014/12/29.
 */
public class ShopInfo {

	private String Shop_id;// 店铺id
	private String Shop_name;// 店铺名
	private String Shop_area;// 店铺区域
	private int Distance;// 距离
	private ArrayList<CouponDetail> coupon_lists;

	public String getShop_id() {
		return Shop_id;
	}

	public void setShop_id(String shop_id) {
		Shop_id = shop_id;
	}

	public String getShop_name() {
		return Shop_name;
	}

	public void setShop_name(String shop_name) {
		Shop_name = shop_name;
	}

	public String getShop_area() {
		return Shop_area;
	}

	public void setShop_area(String shop_area) {
		Shop_area = shop_area;
	}

	public int getDistance() {
		return Distance;
	}

	public void setDistance(int distance) {
		Distance = distance;
	}

	public ArrayList<CouponDetail> getCoupon_lists() {
		return coupon_lists;
	}

	public void parse(JSONObject obj) {
		setShop_id(getString(obj, "shop_id"));// private String Shop_id;//店铺id
		setShop_name(getString(obj, "shop_name"));// private String Shop_name
													// ;//店铺名
		setShop_area(getString(obj, "shop_area"));// private String Shop_area
													// ;//店铺区域
		setDistance(getInt(obj, "distance"));// long Distance;// 距离

		try {
			coupon_lists = new ArrayList<CouponDetail>();
			JSONArray array = obj.getJSONArray("coupon_list");
			for (int i = 0; i < array.length(); i++) {
				JSONObject data = array.getJSONObject(i);
				CouponDetail detail = new CouponDetail();
				detail.parse(data);
				this.coupon_lists.add(detail);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	public int getInt(JSONObject obj, String id) {
		try {
			if (obj.has(id)) {
				return obj.getInt(id);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return 0;
	}

	public String getString(JSONObject obj, String id) {
		try {
			if (obj.has(id)) {
				return obj.getString(id);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((Shop_id == null) ? 0 : Shop_id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ShopInfo other = (ShopInfo) obj;
		if (Shop_id == null) {
			if (other.Shop_id != null)
				return false;
		} else if (!Shop_id.equals(other.Shop_id))
			return false;
		return true;
	}

}
